package com.znyj.cloud.chain.server;

import com.znyj.cloud.device.pack.AtomicValues;
import com.znyj.cloud.device.service.ReportService;
import com.znyj.cloud.device.service.TaskService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by gaoliwei02 on 17/6/12.
 */
@Component
public class ServerInit {
    private static final Logger logger = Logger.getLogger(ServerInit.class);
    private long orderId;

    @Resource
    private TaskService taskService;

    @Resource
    private ReportService reportService;

    public void init() {
        //获取orderId本地数据库记录值
        orderId = taskService.findNewestOrderId();
        AtomicValues.swapOrderId(orderId);
        logger.info("orderId init num: " + orderId);

        //把所有数据库设备下线，防止在线bug
        reportService.initOfflineDevice();
        logger.info("offline all device");
    }
}
